package com.spring.demo.security;

import java.io.IOException;

import javax.annotation.Resource;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler;
import org.springframework.stereotype.Component;

/**
 * 登录授权失败后跳转到的类
 * @author ld2016
 *
 */
@Component("myAuthenticationFailureHandler")
public class MyAuthenticationFailureHandler extends SimpleUrlAuthenticationFailureHandler {

	/*@Resource(name = "myAuthenticationEntryPoint")
	private MyAuthenticationEntryPoint loginEntry;*/
	
	@Override
	public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
			AuthenticationException exception) throws IOException, ServletException {
		// TODO Auto-generated method stub
		//String authenFailureUrl = this.loginEntry.determineUrlToUseForThisRequest(request, response, exception);
		String authenFailureUrl = "/login.do";
		authenFailureUrl += "?error";
		super.setDefaultFailureUrl(authenFailureUrl);
		super.onAuthenticationFailure(request, response, exception);
	}

}
